package com.imooc.Service;

import com.imooc.Dao.GirlDao;
import com.imooc.Exception.GirlException;
import com.imooc.domain.Girl;
import com.imooc.enums.ResultENum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created  on 18-6-28 下午2:37.
 * 作者: Dengjb
 * 说明:
 */
@Service
public class GirlService {
	@Autowired
	private GirlDao girlDao;

	@Transactional
	public void saveTwo( ){
		Girl girl1 = new Girl();
		Girl girl2 = new Girl();
		girl1.setAge(18);
		girl2.setAge(18);
		girl1.setName("hanmei");
		girl2.setName("lilei");
		girlDao.save(girl1);
		girlDao.save(girl2);
	}
	public void getAge( Integer id) throws Exception{
		Girl girl = girlDao.findOne(id);
		Integer age = girl.getAge();
		if(age<10){
//			throw new Exception("小于10岁");
			throw new GirlException(ResultENum.PRIMARY_CODE);
		}
		if(age>10 && age<16){
			throw new GirlException(ResultENum.NORMAL_CODE);
//			throw new Exception("小于16岁大于10岁");
		}
	}
	public Girl findOne( Integer id) {

		return girlDao.findOne(id);
	}
}
